package tests;

import junit.framework.Assert;

import org.junit.*;

import entities.FinancialInfo;
import entities.Loan;
import entities.Student;

/**
 * tests for students and student related information
 * 
 * @author gke703
 */
public class TestStudent {

	/**
	 * tests student initialization
	 */
	@BeforeClass
	public static void Initialize() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getID() == 0
				&& student.getPassword() == "abc");
	}

	/**
	 * The rest of the tests test various methods of student/person
	 */
	@Test
	public void testGetInstitution() {
		Student student = new Student(0, "abc");
		student.setInstitution("U of S");
		Assert.assertTrue(student.getInstitution() == "U of S");
	}

	@Test
	public void testGetIsCitizen() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getIsCitizen());
		student.setCitizenship(false);
		Assert.assertTrue(!student.getIsCitizen());
	}

	@Test
	public void testGetMaritalStatus() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getMaritalStatus() == Student.maritalStatuses.SINGLE);
		student.setMaritalStatus(Student.maritalStatuses.MARRIED);
		Assert.assertTrue(student.getMaritalStatus() == Student.maritalStatuses.MARRIED);
	}

	@Test
	public void testGetFatherEducation() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getFatherEducation() == Student.education.NONE);
		student.setFatherEducation(Student.education.DEGREE);
		Assert.assertTrue(student.getFatherEducation() == Student.education.DEGREE);
	}

	@Test
	public void testGetMotherEducation() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getMotherEducation() == Student.education.NONE);
		student.setMotherEducation(Student.education.DEGREE);
		Assert.assertTrue(student.getMotherEducation() == Student.education.DEGREE);
	}

	@Test(expected = RuntimeException.class)
	public void testGetSIN() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getSIN() == null);
		student.setSIN("1234"); // test wrong size
		student.setSIN("123a123");
		student.setSIN("123123123");
		Assert.assertTrue(student.getSIN().equals("123123123"));
	}

	@Test(expected = RuntimeException.class)
	public void testGetFinances() {
		// test FinancialInfo as well
		Student student = new Student(0, "abc");
		FinancialInfo myf = new FinancialInfo();
		student.setFinances(myf);
		Assert.assertTrue(student.getFinances() == myf);
		myf.setChildSupport(-23);// should throw exception
		Assert.assertTrue(myf.getChildSupport() == 0);
		myf.setChildSupport((float) 100.30);
		Assert.assertTrue(myf.getChildSupport() == 100.30);

		myf.setHouseholdIncome(-3);// should throw exception
		Assert.assertTrue(myf.getHouseholdIncome() == 0);
		myf.setHouseholdIncome((float) 100.39);
		Assert.assertTrue(myf.getHouseholdIncome() == 100.39);

		myf.setMonthlyExpenses(-23);// should throw exception
		Assert.assertTrue(myf.getMonthlyExpenses() == 0);
		myf.setMonthlyExpenses((float) 100.30);
		Assert.assertTrue(myf.getMonthlyExpenses() == 100.30);

		myf.setPersonalIncome(-63);// should throw exception
		Assert.assertTrue(myf.getPersonalIncome() == 0);
		myf.setPersonalIncome((float) 100.90);
		Assert.assertTrue(myf.getPersonalIncome() == 100.90);

		myf.setScholarship(-73);// should throw exception
		Assert.assertTrue(myf.getScholarship() == 0);
		myf.setScholarship((float) 100.09);
		Assert.assertTrue(myf.getScholarship() == 100.09);

		myf.setTaxableEarnings(-83);// should throw exception
		Assert.assertTrue(myf.getTaxableEarnings() == 0);
		myf.setTaxableEarnings((float) 100.30);
		Assert.assertTrue(myf.getTaxableEarnings() == 100.30);

		Assert.assertTrue(myf.getMonthlyIncome() == myf.getHouseholdIncome() / 12);

	}

	@Test(expected = RuntimeException.class)
	public void testGetLoan() {
		// test loan as well
		Student student = new Student(0, "abc");
		Loan l = new Loan(student);
		Assert.assertTrue(student.getLoan() == null);
		student.setLoan(l);

		Assert.assertTrue(l.getStudent() == student);
		Assert.assertTrue(student.getLoan() == l);

		Assert.assertTrue(l.isNew() && !l.isApproved());

		l.setAmountGiven(-23);// exception should be thrown
		Assert.assertTrue(l.getAmountGiven() == 0);
		l.setAmountGiven(900);
		Assert.assertTrue(l.getAmountGiven() == 900);

		l.setAmountRequested(-23);// exception should be thrown
		Assert.assertTrue(l.getAmountRequested() == 0);
		l.setAmountRequested(9000);
		Assert.assertTrue(l.getAmountRequested() == 9000);

		l.setApproval(true);
		Assert.assertTrue(l.isApproved());
		l.setIsNew(false);
		Assert.assertTrue(!l.isNew());

	}

	@Test
	public void testGetPassword() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getPassword().equals("abc"));

	}

	@Test
	public void testGetName() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getName() == "");
		student.setName("g");
		Assert.assertTrue(student.getName().equals("g"));
	}

	@Test
	public void testGetBirthdate() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getBirthdate() == null);
		student.setBirthdate("jhk");
		Assert.assertTrue(student.getBirthdate() == null);
		student.setBirthdate("02/13/1960");
		Assert.assertTrue(student.getBirthdateAsString().equals("02/13/1960"));

	}

	@Test
	public void testGetAddress() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getAddress() == null);
		student.setAddress("190 somewhere");
		Assert.assertTrue(student.getAddress().equals("190 somewhere"));
	}

	@Test
	public void testGetPhoneNumber() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getPhoneNumber() == null);
		student.setPhoneNumber("967-9999");
		Assert.assertTrue(student.getPhoneNumber().equals("967-9999"));
	}

	@Test
	public void testGetEmail() {
		Student student = new Student(0, "abc");
		Assert.assertTrue(student.getEmail() == null);
		student.setEmail("gke703");
		Assert.assertTrue(student.getEmail().equals("gke703"));
	}

}
